Skip to content

[GH-3560] Read the X and Y bounds of a GeoParquet bbox that has Z or M bounds - #3561

Merged
jiayuasu merged 2 commits into
apache:masterfrom
jiayuasu:fix/geoparquet-bbox-with-z
Nov 19, 2026
Merged

jiayuasu merged 2 commits into
apache:masterfrom
jiayuasu:fix/geoparquet-bbox-with-z

Conversation

@jiayuasu

@jiayuasu jiayuasu commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Did you read the Contributor Guide?

Is this PR related to a ticket?

What changes were proposed in this PR?

The bbox of a geometry column in GeoParquet metadata lists the minimum of every dimension and then the maximum of every dimension: four values for XY, six for XYZ, and in GeoParquet 2.0 eight for XYZM. The spatial filter of the geoparquet reader read positions 0 to 3 as xmin, ymin, xmax and ymax whatever the length, so for a six-value bbox it took zmin for xmax. A pushed-down filter then pruned a file that holds matching rows, and the query returned too few rows.

Sedona's writer stores four values, so this shows with files from other writers. GDAL 3.13.1 stores six values for geometries with Z.

GeoParquetSpatialFilter.LeafFilter now takes X and Y from a bbox of four, six or eight values. A file whose bbox has another number of values is kept, where the filter used to fail with an IndexOutOfBoundsException for fewer than four values.

The filter also keeps a file whose bbox crosses the antimeridian. RFC 7946, which the GeoParquet specification follows for bbox, lists the west bound first for such a box, so xmin is greater than xmax, for example [170, -5, -170, 5]. The filter used to build an envelope from the two values, which sorts them into -170 to 170 and leaves out a point at 179°E. That happened for a four-value bbox before this PR; reading the right positions of a six-value bbox would have brought it to those files as well. A bbox whose bounds are not in order for another reason, NaN included, keeps the file too.

Not in this PR: the writer still stores four values for a column with Z.

How was this patch tested?

GeoParquetSpatialFilterPushDownSuite has new tests:

  • The filter keeps and prunes on the X and Y bounds of a bbox with four, six and eight values. The boxes have different upper bounds for X and Y, and one window is inside by Y only, so a mix-up of the two is caught.
  • A bbox that crosses the antimeridian keeps the file, with four, six and eight values.
  • A bbox with bounds that are not in order, or with another number of values, keeps the file.
  • A filter on a file written by GDAL from three points with Z returns the matching row. The file is geoparquet/gdal/point-z.parquet in the test resources, 3 KB.

The tests for Z bounds, the antimeridian and unordered bounds fail without the change.

The GeoParquet suites pass locally on Spark 4.2 / Scala 2.13 and Spark 4.1 / Scala 2.13. On Spark 3.5 / Scala 2.12 I ran GeoParquetSpatialFilterPushDownSuite, GeoParquetMetadataTests and geoparquetIOTests.

Did this PR include necessary documentation updates?

  • No, this PR does not affect any public API so no need to change the documentation.

… Z or M bounds

The bbox of a geometry column lists the minimum of every dimension and
then the maximum of every dimension: four values for XY, six for XYZ and
eight for XYZM. The spatial filter read positions 0 to 3 as xmin, ymin,
xmax and ymax, so it took zmin for xmax in a six-value bbox. A file
written by GDAL from geometries with Z was pruned by a filter that
matches its rows, and the query returned too few rows.

The filter now takes X and Y from a bbox of four, six or eight values
and keeps a file whose bbox has another number of values.
RFC 7946 lists the west bound of such a bbox first, so its xmin is
greater than its xmax. The spatial filter built an envelope from the two
values, which sorts them, and pruned a file with matching rows. That
already happened for a bbox with four values; reading the right positions
of a bbox with six values brought it to those files too. The filter now
keeps a file whose bounds are not in order, NaN included.

The bboxes in the tests have different upper bounds for X and Y, and one
window is inside by Y only, so that the tests tell the two apart.
@jiayuasu jiayuasu added this to the sedona-2.0.0 milestone Nov 19, 2026
@jiayuasu
jiayuasu merged commit e3cb8ed into apache:master Nov 19, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GeoParquet spatial filter drops matching rows when the bbox of a column has Z bounds

1 participant